package org.dtrd.modules.record.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.dtrd.modules.record.entity.bean.AvgRecordBean;
import org.dtrd.modules.record.entity.bean.SugarStatisticsBean;
import org.dtrd.modules.record.entity.bean.SugarValueLineBean;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninSugarValue;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface DtrdEntRdSugarValueMapper extends BaseMapper<DtrdEntRdSigninSugarValue> {

    List<DtrdEntRdSigninSugarValue> getBloodSugarRecordsForCharts(@Param("patientId") int patientId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("sourceType") int sourceType);

    SugarStatisticsBean selectSugarStatisticsByRecordTypes(@Param("patientId") int patientId, @Param("recordTypes") String recordTypes, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("limitLow") float limitLow, @Param("limitHigh") float limitHigh);

    Integer getSugarRecordDateCount(@Param("patientId") int patientId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("sourceType") Integer sourceType);

    List<DtrdEntRdSigninSugarValue> getAllGroupedSugarValues(@Param("patientId") int patientId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("sourceType") Integer sourceType);

    int getSugarRecordCountByPatientIdDate(@Param("patientId") int patientId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    SugarStatisticsBean getPatientSugarStatisticsValueByRecordType(@Param("patientId") int patientId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("recordType") int type);

    /**
     * 查询指定血糖记录
     *
     * @param userId
     * @param recordType 记录类型
     * @param recordTime 记录时间
     * @param timeType   时段类型 区分早午晚餐
     * @param sugar
     * @return
     */
    DtrdEntRdSigninSugarValue getXtySugarRecord(@Param("patientId") Integer userId, @Param("sourceType") Integer recordType, @Param("recordTime") String recordTime, @Param("timeType") Integer timeType, @Param("value") Double sugar);

    /**
     * 计算指定类型平均值
     *
     * @param patientId
     * @param startOfWeek
     * @param endOfWeek
     * @param timeTypes
     * @return
     */
    Float getAvgSugarRecordByTimeTypes(@Param("patientId") Integer patientId, @Param("startDate") String startOfWeek, @Param("endDate") String endOfWeek, @Param("timeTypes") String timeTypes);

    /**
     * 计算时间段内各时段血糖平均值
     *
     * @param patientId
     * @param startDate
     * @param endDate
     * @return
     */
    List<AvgRecordBean> getAvgSugarRecord(@Param("patientId") Integer patientId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 查询血糖列表数据
     */
    List<SugarValueLineBean> pageSugarRecords(@Param("patientId") Integer patientId,
                                              @Param("startTime") Date startTime,
                                              @Param("endTime") Date endTime,
                                              @Param("timeType") Integer timeType,
                                              @Param("sourceType") Integer sourceType,
                                              @Param("orderType") Integer orderType);

    /**
     * 查询患者指定类型最近一条血糖记录
     *
     * @param patientIds (1,2,3)
     * @param timeTypes  1,2,3
     * @return
     */
    List<DtrdEntRdSigninSugarValue> getLatestSugarValue(@Param("patientIds") String patientIds, @Param("timeTypes") int[] timeTypes);

    /**
     * 查询患者指定类型的最初的一个记录数据
     * @param patientId
     * @param timeTypes
     * @return
     */
    Float getFirstSugarValue(@Param("patientId") Integer patientId,@Param("timeTypes") String timeTypes);
}